FROM golang:1.17-alpine as builder
WORKDIR /app
COPY  . .
RUN ls; \
    go env -w GO111MODULE="on"; \
    go env -w GOPROXY="https://goproxy.cn,direct"; \
    go mod tidy; \
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o  bin/httpserver .

# 为方便k8s上使用，改为alpine
FROM alpine
# 测试添加标签
LABEL version="1.4" multi.label1='Multi-stage build httpserver' author='windCoder'
# glog日志会自动写入tmp文件夹下面，没有将会报错 no such file or directory
# 将第一步编译结果导入
WORKDIR /app
COPY --from=builder /app/bin/httpserver /app
EXPOSE 8080
ENTRYPOINT ["/app/httpserver"]